|
|
|
|
|
|
|
application's common code module (see Listing 15.6). Then, in the application's exit routine, you need to add the following code line in place of the Unload statement: |
|
|
|
|
|
|
|
|
PostMessage Me.hwnd, WM_CLOSE, 0&, 0& |
|
|
|
|
|
|
|
|
LISTING 15.6. SYSAPI.TXTUSING WINDOWS API CALLS SO THE SYSTEM TRAY CONTROL CAN WORK. |
|
|
|
 |
|
|
|
|
1: Public Declare Function SetForegroundWindow Lib user32 (ByVal hwnd As _
2: Long) As Long
3: Public Declare Function PostMessage Lib user32 Alias PostMessageA _
4: (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal
5: lParam As Long) As Long
6: Public Const WM_USER = &H400&
7: Public Const WM_CLOSE = &H10& |
|
|
|
|
|
|
|
|
Now, run the application to see how the control works by hiding the application and then double-clicking the tray icon to redisplay it. |
|
|
|
|
|
|
|
|
If the only function that you can perform with the SysTray control was the one described in the preceding section, it would be a pretty good control. In addition to the basic capability that you've added, you can also add support to display application menu items as pop-ups for the tray icon without displaying the entire application. By using the menus, you can display any non-child form in the application for users to access. |
|
|
|
|
|
|
|
|
To add pop-up menu capability, you would add the code in Listing 15.7 to the sysAdTray_MouseUp event routine. |
|
|
|
|
|
|
|
|
LISTING 15.7. SYSMENU.TXTADDING POP-UP MENU PROCESSING TO THE SYSTRAY CONTROL. |
|
|
|
 |
|
|
|
|
1: Private Sub sysAdTray_MouseUp(Button As Integer, Id As Long)
2: SetForegroundWindow and PostMessage (WM_USER) must wrap all
popup menu's
3: ' in order to work correctly with the Notification Icons
4: SetForegroundWindow Me.hwnd
5:
6: Select Case Button
7: Case vbRightButton
8: Me.PopupMenu mnuHelp, vbPopupMenuRightButton
9: Case vbLeftButton
10: Me.PopupMenu mnuFile, vbPopupMenuRightButton
11: End Select
|
|
|
|
|
|